<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>

<script>
    /**
     * 2、根据Date对象获取当前的日期和时间，根据不同时间段显示不同的问候语
     * function greeting(hour){
        if(hour < 6){return "凌晨好！"}
        else if (hour < 9){return "早上好！";}
        else if (hour < 12){return "上午好！";}
        else if (hour < 14){return "中午好！";}
        else if (hour < 17){return "下午好！";}
        else if (hour < 19){return "傍晚好！";}
        else if (hour < 22){return "晚上好！";}
        else {return "夜里好！";}
        }
     */
    var toay = new Date();
    var hour = toay.getHours();

    function greeting(hour) {

        if (hour >= 0 && hour < 6) {
            return "凌晨好，现在是" + hour + "点！";
        } else if (hour >= 6 && hour < 9) {
            return "早上好，现在是" + hour + "点！";
        } else if (hour >= 9 && hour < 12) {
            return "上午好，现在是" + hour + "点！";
        } else if (hour >= 12 && hour < 14) {
            return "中午好，现在是" + hour + "点！";
        } else if (hour >= 14 && hour < 17) {
            return "下午好，现在是" + hour + "点！";
        } else if (hour >= 17 && hour < 22) {
            return "晚上好，现在是" + hour + "点！";
        } else {
            return "夜里好，现在是" + hour + "点！";
        }

    }

    var greet = greeting(hour);
    document.write(greet);

</script>
</body>
</html>